﻿@using System
@using YYBlog.Core.Entity
@using YYBlog.Core.Extensions
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<YYBlog.Core.ViewProjections.Admin.AllBlogPostsViewModel>
@{
    Layout = "_AdminLayout.cshtml";
}
<div class="title">文章管理</div>

<div class="mb-4 tools w-100">
    <div class="btn-group">
        <a href="/yy-admin/posts" class="btn btn-secondary btn-sm">文章</a>
        <a href="/yy-admin/tags" class="btn btn-secondary btn-sm">标签</a>
    </div>
    <div class="float-right"><a href="/yy-admin/posts/new" class="btn btn-danger">写文章</a></div>
</div>
<div class="card article">
    <div class="card-body">
        <table class="table table-striped table-hover">
            <thead class="thead-light">
                <tr>
                    <th>序号</th>
                    <th width="400">标题</th>
                    <th>日期</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var blogPost in Model.Posts)
                {
                    <tr>
                        <th scope="row">@blogPost.Id</th>
                        <td>@blogPost.Title</td>
                        <td>@blogPost.PubDate</td>
                        <td>
                            @if (blogPost.Status == PublishStatus.Draft)
                            {
                            <span class="badge badge-secondary"><i class="fa fa-close"></i></span>
                            }
                            else if (blogPost.PubDate > DateTime.UtcNow)
                            {
                            <span class="badge badge-success"><i class="fa fa-check"></i></span>
                            }
                        </td>
                        <td>
                            <a href="/yy-admin/posts/edit/@blogPost.Id" class="btn btn-primary btn-sm"><i class="fa fa-edit"></i></a>
                            <a href="/yy-admin/posts/delete/@blogPost.Id" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div class="card-footer">
        <nav aria-label="Page navigation example">
            <ul class="pagination justify-content-end">
                @if (Model.HasPrevPage)
                {
                    <li class="page-item disabled">
                        @if (Model.Page == 2)
                        {
                            <a class="page-link" href="/yy-admin/posts/" title="较新的"><i class="fa fa-arrow-circle-left"></i></a>
                        }
                        else
                        {
                            <a href="/yy-admin/posts/@(Model.Page - 1)" title="较新的"><i class="fa fa-arrow-circle-left"></i></a>
                        }
                    </li>
                }
                @if (Model.HasNextPage)
                {
                    <li class="page-item">
                        <a class="page-link" href="/yy-admin/posts/@(Model.Page + 1)" title="较旧的"><i class="fa fa-arrow-circle-right"></i></a>
                    </li>
                }
            </ul>
        </nav>
    </div>
</div>
